package app.util;

import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;

import app.handler.HelloHandler;

public class ManyContexts {

	public static void main(String[] args) throws Exception {
		Server server = new Server(8083);
		
		ContextHandler context = new ContextHandler();
		context.setContextPath("/");
		context.setHandler(new HelloHandler("index page"));
		
		ContextHandler adminContext = new ContextHandler();
		adminContext.setContextPath("/admin");
		adminContext.setHandler(new HelloHandler("admin page"));
		
		ContextHandler userContext = new ContextHandler();
		userContext.setContextPath("/user");
		userContext.setHandler(new HelloHandler("user page"));
		
		ContextHandler virtualContext = new ContextHandler();
		virtualContext.setVirtualHosts(new String[] {"127.0.0.2"});
		virtualContext.setContextPath("/");
		virtualContext.setHandler(new HelloHandler("virtual index page"));
		
		ContextHandlerCollection contexts = new ContextHandlerCollection();
		contexts.setHandlers(new Handler[] {context, adminContext, userContext, virtualContext});
		
		server.setHandler(contexts);
		server.start();
		server.join();
	}
}
